﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using TUlingWpf.Heplers;
using TUlingWpf.Models;

namespace TUlingWpf.ViewModels
{
    public partial class MainWindowViewModel : ObservableObject
    {
        public MainWindowViewModel()
        {
            InitSQl();
        }

        private void InitSQl()
        {
            bool isTableExit = SqlSugarHelper.Db.DbMaintenance.IsAnyTable("用户表", false);
            if (!isTableExit)
            {
                //不存在则创建
                SqlSugarHelper.Db.CodeFirst.As<User>("用户表").InitTables<User>();
                //插入初始数据
                List<User> users = new List<User>()
                {
                    new User(){ Name="admin",Password="admin123",Level=5 ,CreateTime=DateTime.Now },
                     new User(){ Name="test",Password="1",Level=5 ,CreateTime=DateTime.Now },
                      new User(){ Name="李四",Password="123",Level=5 ,CreateTime=DateTime.Now },
                       new User(){ Name="1",Password="1",Level=5 ,CreateTime=DateTime.Now },
                        new User(){ Name="操作员",Password="1",CreateTime = DateTime.Now,Level = 5}
                };
                var res = SqlSugarHelper.Db.Insertable(users).AS("用户表").ExecuteCommand();
            }
        }
    }
}